
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_DGRAM)
serverSocket.bind(('192.168.124.17', serverPort))  # ('192.168.124.17', serverPort) is a tuple

print('The server is ready to receive: ')
i = 1

while True:
    message, clientAddress = serverSocket.recvfrom(2048)

    while i > 0:
        print(clientAddress)
        print("The data type of clientAddress is :", type(clientAddress))
        i -= 1

    print(message)
    # python对bytes类型的数据用带b前缀的单引号或双引号表示：
    print(type(message))  # <class 'bytes'>
    print(message.decode())

    modifiedMessage = message.decode().upper()
    # print(modifiedMessage)

    serverSocket.sendto(modifiedMessage.encode(), clientAddress)
    # The server must attach a destination address to the packet before dropping it into the socket.
